home *** CD-ROM | disk | FTP | other *** search
/ Computer Music Interactif…cial Edition 1999 Winter / cd 3.iso / mac / Mac / Shares / Midishare™1.68 / Development Tools / Smalltalk / MidiShareInterface.doc < prev    next >
Encoding:
Text File  |  1995-10-10  |  5.1 KB  |  96 lines  |  [TEXT/ttxt]

  1.  
  2. Smalltalk\Objectworks™ R4.1 Midi Primitives
  3.  
  4. Macintosh System7, GRAME's MidiShare™ and (optional) Apple's MidiManager
  5. André Ch. Schnoor, Hamburg (Germany)
  6. czesanne@mail.hh.provi.de
  7. czesanne@proaudio.de
  8.  
  9. This source is public domain. You may distribute, use and modify this material as you like. 
  10.  
  11. You need Objectworks\Smalltalk™ R4.1 from ParcPlace Systems as well as a copy of the GRAME MidiShare™ 1.68 package (which is freely available from ftp.grame.fr). You also need a MPW Workbench to compile the C-code and link it together with the Smalltalk virtual machine. I have encountered problems linking the st-80.lib using other C-Compilers because this library is full of MPW C specific stuff - may be it's possible for a real C-freak to port this code.
  12.  
  13. Please keep me informed of any future modifications and developments based on this material.
  14.  
  15. Subject
  16.  
  17. The included C source code implements system primitives for the Objectworks\Smalltalk-80™ virtual machine for interfacing the MidiShare™ real-time midi engine on the Apple Macintosh. This code was tested with MidiShare™ 1.68 and Objectworks\Smalltalk 4.1™ (ParcPlace). The interface was originally developed for the LEVIATHAN™ music composition system. You may change all the strings containing "Leviathan" in the source to any name you like.
  18.  
  19. Features
  20.  
  21. The Smalltalk primitives allow asynchronous midi in/out with comfortable sequencer-like start/stop/tempo control. Only the following event types have been included yet: NOTES, CONTROL CHANGES, PROGRAM CHANGES. This will suit for most applications that deal with music composition rather than studio integration. The interface uses comfortable sequencer-ticks and beats-per-minute values instead of milliseconds which are internally used by MidiShare™.
  22.  
  23. MidiManager Bridge 
  24.  
  25. A bridge to the Apple MidiManager has been included. This allows to control instruments which are connected internally (e.g. SampleCell II™ Soundcards) rather than beeing plugged into the external midi interface. When the Smalltalk midi interface is "opened", an icon representing the Smalltalk midi in/out appears in the midi patchbay control panel. The user can then make the desired connections to other instruments. You may refer to the two MidiManager ports by using the constants
  26.  
  27.     MidiShareInterface midiManagerPort0
  28.     MidiShareInterface midiManagerPort1
  29.  
  30. as the port parameter when sending events.
  31.  
  32. Compilation
  33.  
  34. The C-primitives can be compiled with the included makefile using the MPW. The procedure of adding user primitives to the Smalltalk virtual machine is explained in detail in the Objectworks manual. The makefile automatically links the compiled code together with the virtual machine (select "Build..." from the MPW menu and enter "st80-midi"). The file "MidiShare.h" needs to be placed in the same folder together with the complete stuff from ParcPlace (userprim.h, st80.lib etc).
  35.  
  36. It is very important to adjust the correct memory sizes (command-I) for the new virtual machine executable. Otherwise the new Smalltalk VM would not launch.
  37.  
  38. Smalltalk Part
  39.  
  40. The included Smalltalk class "MidiShareInterface" handles the communication with MidiShare™. Simply create a new instance of this class and use it for communicating with MidiShare. The following methods are implemented:
  41.  
  42. open
  43.     Simply opens the connection to MidiShare™. If Apple MidiManager is
  44.     installed, an icon representing the Smalltalk midi interface will
  45.     appear in the MidiPatchbay control panel.
  46.     
  47. offset: o tempo: t resolution: resolution delay: ms
  48.     Defines the timing constants to be used while playing/recording with
  49.     MidiShare™. The required units are: 
  50.         offset = sequencer ticks,
  51.         resolution = sequencer ticks p. 4/4 (e.g. 1920), 
  52.         tempo = BPM (e.g. 120),
  53.         delay = milliseconds.
  54.     The offset will be subtracted from all event timestamps. This allows
  55.     instant playback of later events without modifying the events.
  56.     
  57. primSend: clock port: port chan: chan type: type data1: d1 data2: d2 data3: d3
  58.     Sends a midi event. The timestamp is given in sequencer ticks instead
  59.     of milliseconds. The C-Primitive will convert these values to milliseconds.
  60.     This is much faster and convenient than doing all this in Smalltalk.
  61.     
  62.         clock    =    sequencer tick-position of the event
  63.         port    =    0..8=MidiShare ports, 9,10=MidiManager ports
  64.         chan    =    midi channel
  65.         type    =     MidiShare event type (see MidiShare doc.)
  66.         d1..d3    =    MidiShare event bytes:
  67.             NOTE                            d1=pitch, d2=velocity, d3=duration
  68.             CONTROLLER    d1=controller, d2=value
  69.             PROGRAM            d1=program number
  70.  
  71.     This method was named "prim..." because you may encapsulate it within
  72.     a higher method that is able to deal with your custom event-objects.
  73.     
  74. recordEnable, recordDisable
  75.     Turn on/off the recording of events between start/stop.
  76.     
  77. start
  78.     Start playback (and recording, if enabled)
  79.     
  80. stop
  81.     Stop playback (and recording).
  82.  
  83. received
  84.     Answer a collection of all events that have been received since the
  85.     last start. Since the interface receives raw byte-data, you have to
  86.     implement the method receiveConvert: aByteArray   (private) to 
  87.     convert the raw data into you custom event-objects.
  88.  
  89. close
  90.     Closes the interface.
  91.  
  92. status
  93.     Answer a verbose string showing the current status of the interface.
  94.     
  95.     
  96.